#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/fcntl.h>

int main()
{
	struct flock flock;
	memset(&flock, 0, sizeof(flock));

	flock.l_type = F_WRLCK;
	flock.l_whence = SEEK_SET;
	flock.l_start = 0;
	flock.l_len = 0;

	int fd1 = open("/tmp/tlock", O_RDWR);
	if (fd1 < 0) {
		perror("open");
		_exit(0);
	}

	int fd2 = open("/tmp/tlock", O_RDWR);
	if (fd2 < 0) {
		perror("open");
		_exit(0);
	}

	if (fcntl(fd1, F_SETLKW, &flock) < 0) {
		perror("fcntl 1");
		_exit(EXIT_SUCCESS);
	}

	if (fcntl(fd2, F_SETLKW, &flock) < 0) {
		perror("fcntl 2");
		_exit(EXIT_SUCCESS);
	}

	return EXIT_SUCCESS;
}